﻿using System;
using System.Xml;
using System.Xml.XPath;
using FeedsLibrary.Feeds.Abstract;

namespace FeedsLibrary.Feeds.RSS
{
    internal class RSSItem : AbstractItem
    {
        public RSSItem(string domain, IXPathNavigable nodeItem, DateTime lastBuildDate)
        {
            _lastBuildDate = lastBuildDate;
            LoadStandardAttributes( domain, nodeItem );
            FeedSpecificAttributes( nodeItem );
        }

        public override void FeedSpecificAttributes(IXPathNavigable nodeItem2)
        {
            XmlNode nodeItem = nodeItem2 as XmlNode;
            if (nodeItem["description"] != null)
            {
                Description = nodeItem[ "description" ].InnerText;
            }

            if ( nodeItem[ "pubDate" ] != null )
            {
                string strDate = nodeItem[ "pubDate" ].InnerText;
                PubDate = GetDate( strDate );
            }
            else
            {
                PubDate = _lastBuildDate;
            }
        }
    }
}